<?php
    header("content-type:text/html;charset=utf-8");

    // pie_chart($_SESSION['order_statistics']['unpay'],$_SESSION['order_statistics']['success'],$_SESSION['order_statistics']['unsend'] ,$_SESSION['order_statistics']['all'] ,400,175,250,100);
    // pie_chart(4,5,20,400,240,250,180);
    // $normal = $_SESSION['status']['normal'];
    // $nospeak = $_SESSION['status']['nospeak'];
    // $total = $_SESSION['status']['total'];
    pie_chart(5,6,18,300,200,200,120);
    /**
     * [pie_chart 饼状图]
     * @param  [int]  $unpay   [未付款数]
     * @param  [int]  $success [已完成数]
     * @param  [int]  $send    [未发货数]
     * @param  [int]  $total   [总订单数]
     * @param  [int] $width   [图片宽度]
     * @param  [int] $height  [图片高度]
     * @param  [int] $pie_w   [饼宽]
     * @param  [int] $pie_h   [饼高]
     * @return 返回生成好的饼状图png
     */
    function pie_chart($unpay = 3,$success = 2,$total = 12,$width=400,$height=240,$pie_w=250,$pie_h=180) {

    //1.创建画布
    $img = imagecreatetruecolor($width,$height);
    //参1,2 画布宽和高 
    // var_dump($img);
    //成功后返回图象资源,失败后返回 FALSE 
    //2.准备颜色
    //imagecolorallocate(image, red, green, blue)
    //参1 资源
    //参2,3,4  RGB   : 0-255   0x00~0xff
    $white = imagecolorallocate($img, 255, 255, 255);
    $black = imagecolorallocate($img, 0,0,0);
    $red = imagecolorallocate($img, 255, 0,0);
    $green = imagecolorallocate($img, 0, 255, 0);
    $blue = imagecolorallocate($img, 0, 0,255);
    $yellow = imagecolorallocate($img, 255,255,0);
    $light_r = imagecolorallocate($img, 150, 0,0);
    $light_g = imagecolorallocate($img, 0, 100,0);
    $light_b = imagecolorallocate($img, 20, 20,255);
    $light_y = imagecolorallocate($img, 180, 180,0);

    //3.填充背景
    // imagefill($img, x,y, $color)
    imagefill($img, 0,0, $white);
    //4.作画
    //立体饼状图
    //阴影
    $unpay_angle = ceil(($unpay*360)/$total);
    // echo $unpay_angle;
    $success_angle = ceil(($success*360)/$total)+$unpay_angle;
    // $unsend_angle = ceil(($unsend*360)/$total)+$success_angle ;

    for ($i=0; $i < 30; $i++) { 
        imagefilledarc($img, 200,120-$i, $pie_w,$pie_h, 0,$unpay_angle, $light_y,IMG_ARC_PIE);
        imagefilledarc($img, 200,120-$i, $pie_w,$pie_h, $unpay_angle,$success_angle, $light_g,IMG_ARC_PIE);
        imagefilledarc($img, 200,120-$i, $pie_w,$pie_h,$success_angle,360 ,$light_r,IMG_ARC_PIE);
    }
    imagefilledarc($img, 200,90, $pie_w,$pie_h, 0,$unpay_angle, $yellow,IMG_ARC_PIE);
     imagefilledarc($img, 200,90, $pie_w,$pie_h, $unpay_angle,$success_angle, $green,IMG_ARC_PIE);
     imagefilledarc($img, 200,90, $pie_w,$pie_h,$success_angle,360 ,$red,IMG_ARC_PIE);
    // 5.保存,输出
    header("content-type:image/jpeg");
    imagejpeg($img);
    //imagejpeg($img) imagegif($img)  imagepng($img)
    //6.关闭资源/销毁(施放内存)
    imagedestroy($img);
   }
?>